extern "C" {
    fn printf(_: *const i8, _: ...) -> i32;
    fn srand(__seed: u32);
    fn time(__timer: *mut time_t) -> time_t;
    fn genann_init(inputs: i32, hidden_layers: i32, hidden: i32, outputs: i32) -> *mut genann;
    fn genann_free(ann: *mut genann);
    fn genann_run(ann: *const genann, inputs: *const f64) -> *const f64;
    fn genann_train(
        ann: *const genann,
        inputs: *const f64,
        desired_outputs: *const f64,
        learning_rate: f64,
    );
}
pub type __time_t = i64;
pub type time_t = __time_t;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct genann {
    pub inputs: i32,
    pub hidden_layers: i32,
    pub hidden: i32,
    pub outputs: i32,
    pub activation_hidden: genann_actfun,
    pub activation_output: genann_actfun,
    pub total_weights: i32,
    pub total_neurons: i32,
    pub weight: *mut f64,
    pub output: *mut f64,
    pub delta: *mut f64,
}
pub type genann_actfun = Option<unsafe extern "C" fn(*const genann, f64) -> f64>;
fn main_0(mut _argc: i32, mut _argv: *mut *mut i8) -> i32 {
    (unsafe { printf(b"GENANN example 1.\n\0" as *const u8 as *const i8) });
    (unsafe {
        printf(
            b"Train a small ANN to the XOR function using backpropagation.\n\0" as *const u8
                as *const i8,
        )
    });
    (unsafe { srand(time(core::ptr::null_mut()) as u32) });
    let input: [[f64; 2]; 4] = [
        [0 as i32 as f64, 0 as f64],
        [0 as i32 as f64, 1 as f64],
        [1 as i32 as f64, 0 as f64],
        [1 as i32 as f64, 1 as f64],
    ];
    let output: [f64; 4] = [ 0 as f64, 1 as f64, 1 as f64, 0 as f64,
    ];
    let mut i: i32 = 0;
    let mut ann: *mut genann = unsafe { genann_init(2 as i32, 1, 2, 1) };
    i = 0;
    while i < 500 {
        (unsafe {
            genann_train(
                ann,
                (input[0 as i32 as usize]).as_ptr(),
                output.as_ptr().offset(0 as i32 as isize), 3 as f64,
            )
        });
        (unsafe {
            genann_train(
                ann,
                (input[1 as i32 as usize]).as_ptr(),
                output.as_ptr().offset(1 as i32 as isize), 3 as f64,
            )
        });
        (unsafe {
            genann_train(
                ann,
                (input[2 as i32 as usize]).as_ptr(),
                output.as_ptr().offset(2 as i32 as isize), 3 as f64,
            )
        });
        (unsafe {
            genann_train(
                ann,
                (input[3 as i32 as usize]).as_ptr(),
                output.as_ptr().offset(3 as i32 as isize), 3 as f64,
            )
        });
        i += 1;
    }
    (unsafe {
        printf(
            b"Output for [%1.f, %1.f] is %1.f.\n\0" as *const u8 as *const i8,
            input[0 as i32 as usize][0 as i32 as usize],
            input[0 as i32 as usize][1 as i32 as usize],
            *genann_run(ann, (input[0 as i32 as usize]).as_ptr()),
        )
    });
    (unsafe {
        printf(
            b"Output for [%1.f, %1.f] is %1.f.\n\0" as *const u8 as *const i8,
            input[1 as i32 as usize][0 as i32 as usize],
            input[1 as i32 as usize][1 as i32 as usize],
            *genann_run(ann, (input[1 as i32 as usize]).as_ptr()),
        )
    });
    (unsafe {
        printf(
            b"Output for [%1.f, %1.f] is %1.f.\n\0" as *const u8 as *const i8,
            input[2 as i32 as usize][0 as i32 as usize],
            input[2 as i32 as usize][1 as i32 as usize],
            *genann_run(ann, (input[2 as i32 as usize]).as_ptr()),
        )
    });
    (unsafe {
        printf(
            b"Output for [%1.f, %1.f] is %1.f.\n\0" as *const u8 as *const i8,
            input[3 as i32 as usize][0 as i32 as usize],
            input[3 as i32 as usize][1 as i32 as usize],
            *genann_run(ann, (input[3 as i32 as usize]).as_ptr()),
        )
    });
    (unsafe { genann_free(ann) });
    return 0;
}
pub fn main() {
    let mut args: Vec<*mut i8> = Vec::new();
    for arg in ::std::env::args() {
        args.push(
            (::std::ffi::CString::new(arg))
                .expect("Failed to convert argument into CString.")
                .into_raw(),
        );
    }
    args.push(::core::ptr::null_mut());
    {
        ::std::process::exit(
            main_0((args.len() - 1) as i32, args.as_mut_ptr() as *mut *mut i8) as i32,
        )
    }
}
